<?php
/*
班级管理模块
*/
include_once('include/top.php');

$action=fs_get_value("do");
switch($action)
{
	case	"addclass"	:	addclass()	;	break;
    case    "editclass"    :   editclass()    ;   break;
	case	"deleteclass"	     : deleteclass()	     ; break;
    case    "update_class"  :       update_class()  ;       break;
    case    "adddue"    :   adddue()    ;   break;
    case    "editdue"    :   editdue()    ;   break;
    case    "duemanage"    :   duemanage()    ;   break;
    case    "do_adddue" :   do_adddue() ;   break;
    case    "deletedue" :   deletedue() ;   break;
    case	"department"	     : department()	     ; break;
    case	"editdepartment"	     : editdepartment()	         ; break;
        case	"adddepartment"	     : adddepartment()	         ; break;
	case	"do_adddepartment"	         : do_adddepartment()	     ; break;
	case	"deletedepartment"	     : delete_department()	     ; break;
    case	"searchdepartment"	     : searchdepartment()	     ; break;
    case	"searchmajor"	     : searchmajor()	     ; break;
	default				:	manage()		;	break;
}
?>

<script type="text/javascript">
function Check(){
      if(document.addform.name.value ==  ""){
        alert("请输入班级名称!");
        document.addform.name.focus();
        return  false;
    }
    if(document.addform.dueid.value ==  "-1"){
        alert("请选择届数!");
        document.addform.dueid.focus();
        return  false;
    }
    if(document.addform.departid.value ==  "-1"){
        alert("请选择院系!");
        document.addform.departid.focus();
        return  false;
    }
    if(document.addform.majorid.value ==  "-1"){
        alert("请选择专业!");
        document.addform.majorid.focus();
        return  false;
    }
  
}
</script>
<?php

//***********************************************************
//**********************班级管理*****************************
//***********************************************************
function manage()
{
	global $db;

	//取总条数
    $dueid = fs_get_value("dueid");
    $departid = fs_get_value("departid");
    $majorid = fs_get_value("majorid");
    $name = fs_get_value("name");
	$conditionarray = array($dueid,$departid,$majorid,$name);
	$valuearray = array(" and dueid = '".$dueid."'"," and departmentid = '".$departid."'"," and majorid = '".$majorid."'"," and name like '%".$name."%'");
	$sql = "select * from nettteach_class where 1=1";
	for($i=0;$i<count($conditionarray);$i++ ){
		if($conditionarray[$i] == '-1'||$conditionarray[$i] == ''){
			$valuearray[$i] = '';
		}
		$sql.=$valuearray[$i];
	}
    $sql.=" order by dueid,departmentid";
	$result = $db->query($sql);
	$resultcount = $db->num_rows($result);

	//pagebar
	@$page=fs_get_value('p');							//接收页码
	if ($page==null){$page=1;}
	$pagesize=15;	//每页显示数	
	$pagecount=ceil($resultcount/$pagesize);	//计算总页
	if ($page>$pagecount){$page=$pagecount;}   // 防止用户恶意输入负值或者其他不合理的值
	if ($page<1){$page=1;}
	$startnum=($page-1)*($pagesize);
	//pagebarend

?>
<script src="./js/Main.js"></script>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="CContent">
  <tr>
    <th class="CTitle">班级管理</th>
  </tr>
  <tr>
    <td class="CPanel">
    <div class="SubMenu">
                            <a href="admin_class.php?do=duemanage">届管理</a> | 
                            <a href="admin_class.php?do=adddepartment">添加届</a> |
                            <a href="admin_class.php?do=manage">班级管理</a> |
                            <a href="admin_class.php?do=addclass">添加班级</a>| 
                            <a href="admin_class.php?do=searchmajor">搜索班级</a> </div>
		<form action="admin_class.php?do=deleteclass" method="post" name="fooeeform" style="margin:0px">
		<table border="0" cellpadding="0" cellspacing="0"  class="TablePanel" width="100%">
			<tr align="center" class="TDHead">
			<td nowrap width="8%"><input type=button style="font-size:9pt;width:50px;" value="全选" onclick="click_allid(fooeeform,1)"></td>
			<td nowrap width="8%"><input type=button style="font-size:9pt;width:50px;" value="全取消" onclick="click_allid(fooeeform,0)"></td>
			<td nowrap width="8%"><input type=submit name='delete_class' style="font-size:9pt;width:50px;" value="删除" onclick="return delid()"></td>
			<td nowrap></td>
			<td nowrap></td>
			<td nowrap></td>
			<td width="30%" nowrap></td>
			<td nowrap></td>
			</tr>
		</table>

<div id="click_idall">
    <div align="left" style="padding:5px;">
      <table border="0" cellpadding="0" cellspacing="0" class="TablePanel" align="center" width="100%">
        <tr align="center">
		  <td class="TDHead">√</td>
          <td class="TDHead" nowrap>届</td>   
          <td class="TDHead" nowrap>班级名称</td>   
		  <td class="TDHead" nowrap>所属系</td>
          <td class="TDHead" nowrap>所属专业</td>
		  <td class="TDHead" nowrap>操作</td>
        </tr>
<?php
//print_r($startnum);
	$result=$db->query($sql." limit ".$startnum.",$pagesize");
	while($row = $db->fetch_array($result))
	{
?>
		<tr id=""  onMouseOver="bgColor='#FF8899'" onMouseOut="bgColor='FFFFFF'" title=单击选中 align="center">
            <td height="27"><input name='id[]' type='checkbox' id="" value=<?php echo($row['id']);?>></td>
            <td><?php echo(fs_get_objinfo("nettteach_due","id", $row['dueid'],  "name"));?></td>
            <td><a href="?do=editclass&id=<?php echo($row['id']);?>"><?php echo($row['name']);?></a></td>
            <td><?php echo(fs_get_objinfo("nettteach_department","id", $row['departmentid'],  "name"));?></td>
            <td><?php echo(fs_get_objinfo("nettteach_major","id", $row['majorid'],  "name"));?></td>
            <td><a href="?do=editclass&id=<?php echo($row['id']);?>">编辑</a></td>
		</tr>
		<tr>
			<td height=1 colspan=9 bgcolor="#E8F1FF" onMouseOver="bgColor='#FF8899'" onMouseOut="bgColor='E7E7E7'"></td>
		</tr>
<?php
	}	
?>
	</table></div>
	</div>
	</form>

	<center><?php
/*分页示例:

pager(传入URL , 数据总数 , 开始条数 , 每页数目)
*/
echo(pager('?do=manage&p={page}',$resultcount,$startnum,$pagesize));		
?></center>
	</td>
	</tr>
	</table>

<?php
}	
function addclass(){
?>

<script type="text/javascript">
  function getOptionDEPARTMENT(){
  $.getJSON("option.php",{'departmentid':$("#dueid").val()},function(data){
    $("#departid").html("<option value='-1'>请选择系</option>");
    $("#majorid").html("<option value=''>请选择专业</option>");
    $("#classid").html("<option value=''>请选择班级</option>");
    $.each(data, function(index,array){
     var option="<option value='"+array['id']+"'>"+array['name']+"</option>"; 
     $("#departid").append(option);
    });                
   }); 
 }
 function getOptionMAJOR(){
  $.getJSON("option.php",{'bval':$("#departid").val()},function(data){
    $("#majorid").empty();//每次选择前，清空小类的值。
    $("#classid").empty();
    $("#classid").html("<option value='-1'>请选择班级</option>");
    $("#majorid").html("<option value='-1'>请选择专业</option>");
    $.each(data, function(index,array){
     var option="<option value='"+array['id']+"'>"+array['name']+"</option>"; 
     $("#majorid").append(option);
    });                
   }); 
 }
 $(document).ready(function(){
    $("#dueid").change(function(){
        getOptionDEPARTMENT();
    });
    $("#departid").change(function(){
        getOptionMAJOR();
    });

 });
</script>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="CContent">
		<tr>
		    <th class="CTitle">班级管理</th>
		</tr>	
		<tr>
			<td class="CPanel">
                <div class="SubMenu">
                            <a href="admin_class.php?do=duemanage">届管理</a> | 
                            <a href="admin_class.php?do=adddepartment">添加届</a> |
                            <a href="admin_class.php?do=manage">班级管理</a> |
                            <a href="admin_class.php?do=addclass">添加班级</a>| 
                            <a href="admin_class.php?do=searchmajor">搜索班级</a> </div>
			</td>
		</tr>	
		<tr>
			<td>
			<div class="middle_right_list" style="font-size:13px;">
			<form  action="?do=update_class" method="post" name="addform">
			<fieldset>
				<legend>添加班级</legend><br>             
                        <label>班级名称：</label><input name="name" type="text"  class="text" value="<?php echo($row['name']);?>" style="width:300px" /><br/><br/>
                        <label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;届&nbsp;：</label>       
                        <select name="dueid" id="dueid" style="width:300px;">
                                <option value="-1">请选择届</option>
                                <?php
                                $sql="select* from nettteach_due where 1=1";
                                $result=mysql_query($sql);
                                //循环列出选项
                                        while($rows=mysql_fetch_array($result))
                                {?>
                                        <option value=<?php echo $rows['id']; ?>><?php echo $rows['name'];?></option>
                                <?php } ?>
                        </select> <br/><br/>
                        <label>&nbsp;&nbsp;&nbsp;&nbsp;院系：</label>
                        <select name="departid" id="departid" style="width:300px;">
                                <option value="-1">请选择系</option>
                        </select><br/><br/>
                        <label>&nbsp;&nbsp;&nbsp;&nbsp;专业：</label>
                        <select name="majorid" id="majorid" style="width:300px;">
                                <option value="-1">请选择专业</option>
                        </select><br/><br/>
                        <label></label><input type="submit" class="sub" value="确认提交" onclick="return Check();"/>&nbsp;&nbsp;&nbsp;&nbsp;<a class="lj" href="admin_class.php?do=manage">返回列表</a>
                </fieldset>
			</form>
			</div>
			</td>
		</tr>
	</table>
<?php
}	
function editclass(){
    global $db;
	$class_id = fs_get_value("id");
	if($class_id != ''){
		$sql ="select * from " .TABLE_CLASS." where id=".$class_id;
        $result=$db->query($sql);
        $row=$db->fetch_array($result);
	}
?>
<script type="text/javascript">
 function getOptionMAJOR(){
  $.getJSON("option.php",{'bval':$("#departid").val()},function(data){
    $("#majorid").empty();//每次选择前，清空小类的值。
    $("#classid").empty();
    $("#classid").html("<option value='-1'>请选择班级</option>");
    $("#majorid").html("<option value='-1'>请选择专业</option>");
    $.each(data, function(index,array){
     var option="<option value='"+array['id']+"' >"+array['name']+"</option>"; 
     $("#majorid").append(option);
    });                
   }); 
 }
 $(document).ready(function(){
    $("#dueid").change(function(){
        getOptionDEPARTMENT();
    });
    $("#departid").change(function(){
        getOptionMAJOR();
    });

 });
</script>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="CContent">
<?php 

?>
		<tr>
		    <th class="CTitle">班级管理</th>
		</tr>	
		<tr>
			<td class="CPanel">
    <div class="SubMenu">
		<div class="SubMenu">
                            <a href="admin_class.php?do=duemanage">届管理</a> | 
                            <a href="admin_class.php?do=adddepartment">添加届</a> |
                            <a href="admin_class.php?do=manage">班级管理</a> |
                            <a href="admin_class.php?do=addclass">添加班级</a>| 
                            <a href="admin_class.php?do=searchmajor">搜索班级</a> </div>
			</td>
		</tr>	
		<tr>
			<td>
			<div class="middle_right_list" style="font-size:13px;">
            <form  action="?do=update_class&classid=<?php echo($row[id])?>" method="post" name ="addform">
			<fieldset>        
                <legend>编缉班级</legend><br>           
                        <label>&nbsp;&nbsp;班级名称&nbsp;：</label><input name="name" type="text"  class="text" value="<?php echo($row['name']);?>" /><span style="color:#FF0000;">*</span><br/><br/>
                        <label>所属系/专业：</label><?php echo(fs_get_departname($row['departmentid']).'/'.fs_get_majorname($row['majorid']));?><br><br/>
                        <label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;届&nbsp;：</label>       
                        <select name="dueid" id="dueid" style="width:300px;">
                                <?php
                                $sql="select* from nettteach_due where 1=1";
                                $result=mysql_query($sql);
                                //循环列出选项
                                        while($rows=mysql_fetch_array($result))
                                {?>
                                        <option value="<?php echo $rows['id'];?>" <?php if($rows['id']==$row['dueid']){echo "selected";}?>><?php echo $rows['name'];?></option>
                                <?php } ?>
                        </select> <br/><br/>
                        <label>&nbsp;&nbsp;&nbsp;&nbsp;院系：</label>
                        <select name="departid" id="departid" style="width:300px;" >
                                        <option value="-1">请选择系</option>
                                        <?php
                                        $sql="select* from nettteach_department where 1=1";
                                        $result=mysql_query($sql);
                                        //循环列出选项
                                                while($rows=mysql_fetch_array($result))
                                        {?>
                                                <option value="<?php echo $rows['id']; ?>" <?php if($rows['id']==$row['departmentid'])echo 'selected'; ?>><?php echo $rows['name'];?></option>
                                        <?php } ?>
                        </select><br/><br/>
                        <label>&nbsp;&nbsp;&nbsp;&nbsp;专业：</label>
                        <select name="majorid" id="majorid" style="width:300px;">
                             <option value="-1">请选择专业</option>
                                        <?php
                                        $sql="select* from nettteach_major where departmentid=".$row['departmentid'];
                                        $result=mysql_query($sql);
                                        //循环列出选项
                                                while($rows=mysql_fetch_array($result))
                                        {?>
                                        <option value="<?php echo $rows['id']; ?>" <?php if($rows['id']==$row['majorid'])echo 'selected'; ?>><?php echo $rows['name'];?></option>
                                        <?php } ?>
                        </select><br/><br/>
                        <label></label><input type="submit" class="sub" value="确认提交" onclick="return Check();"/>&nbsp;&nbsp;&nbsp;&nbsp;<a class="lj" href="admin_class.php?do=manage">返回列表</a>
                </fieldset>
			</form>
			</div>
			</td>
		</tr>
	</table>
                
</form>

<?php 
}
?>
        </table>
<?php

//根据系ID返回系名称 20120817qzr
function fs_get_departname($i)
{
	if ( $i=='' || is_null($i) || !is_numeric($i))	{return '无';break;}
	global $db;
	$sql	=	"select name from ".TABLE_DEPARTMENT." where id=$i ";
	$result =	$db -> query($sql);
	$row	=	$db -> fetch_array($result);
	return	$row['name'];
}
//根据专业ID返回专业名称 20120817qzr
function fs_get_majorname($i)
{
	if ( $i=='' || is_null($i) || !is_numeric($i))	{return '无';break;}
	global $db;
	$sql	=	"select name from ".TABLE_MAJOR." where id=$i ";
	$result =	$db -> query($sql);
	$row	=	$db -> fetch_array($result);
	return	$row['name'];
}
//添加/修改班级
function update_class(){
        global $db;
	$name = fs_get_value("name");
	$majorid = fs_get_value("majorid");
	$departid = fs_get_value("departid");
    $dueid = fs_get_value("dueid");
//        if($departid != '-1' && $departid != '' &&  $majorid == '-1' )
//        {
//                 fs_showmsg("请选择专业！");
//        }else
//        {
                //添加班级
                if(fs_get_value("classid") == ''){
                        if($name != '' && $departid != '-1'){
                                $num = $db -> row_count("nettteach_class","name = '".$name."'");
                                if($num>0)
                                {
                                        fs_showmsg("该班级名已存在！");
                                        exit();
                                }else
                                {
                                        $sql = "insert into nettteach_class (`name`) value ('".$name."')";
                                        $db->query($sql);
                                        $id = mysql_insert_id();
                                }
                        }else
                        {
                                fs_showmsg("请选择系！");
                                exit();
                        }
                }
                else{
                        //修改班级
                        $id = fs_get_value("classid");
                        $num = $db -> row_count(TABLE_CLASS,"name = '".$name."' and id not in ('".$id."')");
                                if($num>0)
                                {
                                        fs_showmsg("该班级名已存在！");
                                        exit();
                                }
                        if($name != '' ){
                                $sql = "update nettteach_class  set name = '".$name."' where id = ".$id;
                                $db -> query($sql);
                        }
                }
                if($dueid != '-1'){
                        $sql = "update nettteach_class set dueid = ".$dueid." where id = ".$id;
                        $db -> query($sql);
                }
                if($majorid != '-1' && $majorid != ''){
                        $sql = "update nettteach_class set majorid = ".$majorid." where id = ".$id;
                        $db -> query($sql);
                }
                if($departid != '-1'&& $departid != ''){
                        $sql = "update nettteach_class set departmentid = ".$departid." where id = ".$id;
                        $db -> query($sql);
                }
                if(fs_get_value("classid") == ''){
                        fs_showmsg("添加成功！");
                }
                else{
                        fs_showmsg("修改成功！");
                }
//        }
}
?>

	<?php

function deleteclass(){
    global $db;
		if(fs_get_value("id")!=''){
	                $id = fs_get_value("id");
	                if(!is_array($id))
                        {
                                $sql="delete from nettteach_class where id=".fs_get_value("id");
                                $class_sql = "select id from nettteach_member where classid =".fs_get_value("id");
			}else
                        {
                                $str_id = implode(",",$id);
                                $sql="delete from nettteach_class where id in(".$str_id.")";
                                $class_sql = "select id from nettteach_member where classid in(".$str_id.")";
			}
                        $classid  = $db->query($class_sql);
                        $row = mysql_fetch_array($classid);
                        if($row == ''){
                                $result = $db->query($sql);
                                $result? fs_showmsg("删除成功!","admin_class.php?do=manage"):fs_showmsg("删除过程中出现错误,请检查!");
                        }else{
                                fs_showmsg("该班级下有学生,不能删除!","admin_class.php?do=manage");
                        }
                }
}
			?>

<?php
//届管理开始
function duemanage()
{
    global $db;
	$sql = "select * from nettteach_due where 1=1 ";
	$department_result = $db -> query($sql);
	$recordcount = $db -> num_rows($department_result);
	@$page=$_GET['p'];
	if ($page==null){$page=1;}
	$pagesize=10;								//每页显示数
	$pagecount=ceil($recordcount/$pagesize);	//计算总页
	if ($page>$pagecount){$page=$pagecount;}
	if ($page<1){$page=1;}
?><script src="./js/Main.js"></script>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="CContent">
  <tr>
    <th class="CTitle">届管理</th>
  </tr>
  <tr>
    <td class="CPanel">
    <div class="SubMenu">
                            <a href="admin_class.php?do=duemanage">届管理</a> | 
                            <a href="admin_class.php?do=adddepartment">添加届</a> |
                            <a href="admin_class.php?do=manage">班级管理</a> |
                            <a href="admin_class.php?do=addclass">添加班级</a>| 
                            <a href="admin_class.php?do=searchmajor">搜索班级</a> </div>
	<form action="?do=deletedepartment" method="post" name="fooeeform" style="margin:0px">
		<table border="0" cellpadding="0" cellspacing="0"  class="TablePanel" width="100%">
			<tr align="center" class="TDHead">
				<td nowrap><input type=button style="font-size:9pt;width:50px;" value="全选" onclick="click_allid(fooeeform,1)"/></td>
				<td nowrap><input type=button style="font-size:9pt;width:60px;" value="全取消" onclick="click_allid(fooeeform,0)"/></td>
				<td nowrap><input type="submit" style="font-size:9pt;width:50px;" value="删除" onclick="return delid()"/></td>

				<td nowrap width="500"></td>
				<td nowrap>.</td>
				<td nowrap>.</td>
				<td width="30%" nowrap></td>
				<td nowrap></td>
			</tr>
		</table>
<div id="click_idall">
    <div align="left" style="padding:5px;">
      <table border="0" cellpadding="0" cellspacing="0" class="TablePanel" align="center" width="100%">
        <tr align="center">
		  <td class="TDHead">√</td>
          <td class="TDHead" nowrap>届名称</td>
          <td class="TDHead" nowrap>操 作</td>
        <!--  <td class="TDHead" nowrap>登陆记录</td>-->
        </tr>
<?php
	$department_result=$db->query($sql." limit ".($page-1)*($pagesize).",$pagesize");
	while($due_row = $db->fetch_array($department_result))
	{
?>
		<tr id="t<?php echo($due_row["id"]);?>" onclick="click_tr('<?php echo ($due_row["id"]);?>')" onMouseOver="bgColor='#FF8899'" onMouseOut="bgColor='FFFFFF'" title=单击选中 align="center">
			<td height="27"><input name='id[]' type='checkbox' id="c<?php echo($due_row["id"]);?>" value='<?php echo ($due_row["id"]);?>' onclick="click_tr('<?php echo ($due_row["id"]);?>')"></td>
			<td><a href="?do=editdue&due_id=<?php echo ($due_row["id"]);?>"><?php echo($due_row["name"]);?></a></td>
			<td><a href="?do=editdue&due_id=<?php echo ($due_row["id"]);?>">编缉</a></td>
		</tr>
		<tr>
			<td height=1 colspan=10 bgcolor="#E8F1FF" onMouseOver="bgColor='#FF8899'" onMouseOut="bgColor='E7sxE7sxE7sx'"></td>
		</tr>
<?php
	}
?>
	</table>
	</div>
	</div>
	</form>
	
	
	
	<center>
<?php
/*分页示例:

pager(传入URL , 数据总数 , 开始条数 , 每页数目)
*/
echo(pager('?do=duemanage&p={page}',$recordcount,($page-1)*($pagesize),$pagesize));		
?>
                
</center>
	</td>
	</tr>
	</table>

<?php
}
?>
<!--
编缉系开始
-->
<?php
function editdue()
{
    global $db;
	$due_id = fs_get_value("due_id");
	if($due_id != ''){
		$sql = "select * from nettteach_due where id = ".$due_id;
		$department_result = $db -> query($sql);
		$due_row = $db -> fetch_array($department_result);
	}
?>
<script>
function   CheckDepartment(){
     if(document.addform.departmentname.value ==  ""){
        alert("届名不能为空!");
        document.addform.departmentname.focus();
        return  false;
    }
}  
</script>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="CContent">
		<tr>
		    <th class="CTitle">届管理</th>
		</tr>	
		<tr>
			<td class="CPanel">
    <div class="SubMenu">
		<div class="SubMenu">
                            <a href="admin_class.php?do=duemanage">届管理</a> | 
                            <a href="admin_class.php?do=adddepartment">添加届</a> |
                            <a href="admin_class.php?do=manage">班级管理</a> |
                            <a href="admin_class.php?do=addclass">添加班级</a>| 
                            <a href="admin_class.php?do=searchmajor">搜索班级</a> </div>
			</td>
		</tr>	
		<tr>
			<td>
			<div class="middle_right_list" style="font-size:13px;">
			<form name="addform" method="post" action="?do=do_adddepartment&due_id=<?php echo($due_id);?>">
			<fieldset>
				<legend>编辑届</legend><br/><br/>
                    <label>届名称：</label><input name="departmentname" type="text"  class="text" value="<?php echo ($due_row['name'])?>" ><br/><br/>
					<div class="submit">
					<label></label><input type="submit" class="sub" value="确认提交" onclick="return CheckDepartment();"/>&nbsp;&nbsp;&nbsp;&nbsp;<a class="lj" href="admin_class.php?do=duemanage">返回列表</a>
                    </div>
            </fieldset>
			</form>
			</div>
			</td>
		</tr>
	</table>
<?php
}
function do_adddepartment(){
        global $db;
        $departmentname = trim(fs_get_value("departmentname"));
        //添加系
        if($departmentname != '' ){
                if(fs_get_value("due_id") == ''){
                            $sql_check ="select * from nettteach_due where name ='".$departmentname."'";
                            $result= $db->query($sql_check);
                            $resultcount = $db->num_rows($result);
                            if($resultcount == 0){
                                $sql = "insert into nettteach_due (name) value ('".$departmentname."')";
                                $db->query($sql);
                            }else{
                                 fs_showmsg("届名已存在！");
                                 exit();
                            }
                }else{
                        //修改系
                        $id = fs_get_value("due_id");
                        $sql = "update nettteach_due  set name = '".$departmentname."' where id = ".$id;
                        $db -> query($sql);
                }
        }else{
                        fs_showmsg("系名称不能为空！");
                        exit();
        }
        if(fs_get_value("due_id") == ''){
                fs_showmsg("添加成功！");
        }
        else{
                fs_showmsg("修改成功！");
        }
}
?>
<!--
编缉系结束
-->
<!--
添加系开始
-->
<?php
function adddepartment()
{
    global $db;
?>
<script>
function   CheckDepartment(){
     if(document.addform.departmentname.value ==  ""){
        alert("届名不能为空!");
        document.addform.departmentname.focus();
        return  false;
    }
}  
</script>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="CContent">
		<tr>
		    <th class="CTitle">届管理</th>
		</tr>	
		<tr>
			<td class="CPanel">
                <div class="SubMenu">
                   <div class="SubMenu">
                            <a href="admin_class.php?do=duemanage">届管理</a> | 
                            <a href="admin_class.php?do=adddepartment">添加届</a> |
                            <a href="admin_class.php?do=manage">班级管理</a> |
                            <a href="admin_class.php?do=addclass">添加班级</a>| 
                            <a href="admin_class.php?do=searchmajor">搜索班级</a> </div>
			</td>
		</tr>	
		<tr>
			<td>
			<div class="middle_right_list" style="font-size:13px;">
			<form name="addform" method="post" action="?do=do_adddepartment&due_id=<?php echo($due_id);?>">
			<fieldset>
				<legend>添加届</legend><br/><br/>
                    <label>届名称：</label><input name="departmentname" type="text"  class="text" value="" ><br/><br/>
					<div class="submit">
					<label></label><input type="submit" class="sub" value="确认提交" onclick="return CheckDepartment();"/>&nbsp;&nbsp;&nbsp;&nbsp;<a class="lj" href="admin_class.php?do=duemanage">返回列表</a>
                    </div>
            </fieldset>
			</form>
			</div>
			</td>
		</tr>
	</table>
<?php
}
?>
<!--
添加系结束
-->

<?php
//删除届
function delete_department()
{
    global $db;
    $name='';
    $i=0;
	$due_id = $_POST['id'];
        if($due_id != ''){
                while($due_id){
                    if($due_id[$i]==null) break;
                        $sqlmajor = "select * from nettteach_class where dueid = ".$due_id[$i];
                        $sql = "delete from nettteach_due where id = ".$due_id[$i]."";
                        $result = $db -> query($sqlmajor);
                        $result_row = $db -> fetch_array($result);
                        if($result_row['id'] != ''){
                                fs_showmsg("要删除的届下有班级,不能删除");
                        }else{
                                $db -> query($sql);
                        }
                        $i++;
                }
                fs_showmsg("删除成功");
        }else{
                fs_showmsg('请选择要删除的届!');
        }
}
?> 



<?php
function searchmajor()
{
?>
<script type="text/javascript">
 function getOptionMAJOR(){
  $.getJSON("option.php",{'bval':$("#departid").val()},function(data){
    $("#majorid").empty();//每次选择前，清空小类的值。
    $("#classid").empty();
    $("#classid").html("<option value='-1'>请选择班级</option>");
    $("#majorid").html("<option value='-1'>请选择专业</option>");
    $.each(data, function(index,array){
     var option="<option value='"+array['id']+"'>"+array['name']+"</option>"; 
     $("#majorid").append(option);
    });                
   }); 
 }
  function getOptionCLASS(){
  $.getJSON("option.php",{'classid':$("#majorid").val()},function(data){
    $("#classid").empty();//每次选择前，清空小类的值。
    $("#classid").html("<option value='-1'>请选择班级</option>");
    $.each(data, function(index,array){
     var option="<option value='"+array['id']+"'>"+array['name']+"</option>"; 
     $("#classid").append(option);
    });                
   }); 
 }
 $(document).ready(function(){
    $("#departid").change(function(){
        getOptionMAJOR();
    });
    $("#majorid").change(function(){
        getOptionCLASS();
    });
 });
</script>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="CContent">
		<tr>
		    <th class="CTitle">班级管理</th>
		</tr>	
		<tr>
			<td class="CPanel">
                <div class="SubMenu">
                   <div class="SubMenu">
                            <a href="admin_class.php?do=duemanage">届管理</a> | 
                            <a href="admin_class.php?do=adddepartment">添加届</a> |
                            <a href="admin_class.php?do=manage">班级管理</a> |
                            <a href="admin_class.php?do=addclass">添加班级</a>| 
                            <a href="admin_class.php?do=searchmajor">搜索班级</a> </div>
			</td>
		</tr>	
		<tr>
			<td>
			<div class="middle_right_list" style="font-size:13px;">
			<form name="searchform" method="post" action="?do=manageaa" class="CContent">
			<fieldset>
				 <legend>搜索专业</legend><label></label><br>
                    <label>班级名称：</label><input name="name" type="text"  class="text"  style="width:300px" /><br/><br/>
                        <label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;届&nbsp;：</label>       
                        <select name="dueid" id="dueid" style="width:300px;">
                                <option value="-1">请选择届</option>
                                <?php
                                $sql="select* from nettteach_due where 1=1";
                                $result=mysql_query($sql);
                                //循环列出选项
                                        while($rows=mysql_fetch_array($result))
                                {?>
                                        <option value=<?php echo $rows['id']; ?>><?php echo $rows['name'];?></option>
                                <?php } ?>
                        </select> <br/><br/>
                        <label>&nbsp;&nbsp;&nbsp;&nbsp;院系：</label>
                        <select name="departid" id="departid" style="width:300px;" >
                                        <option value="-1">请选择系</option>
                                        <?php
                                        $sql="select* from nettteach_department where 1=1";
                                        $result=mysql_query($sql);
                                        //循环列出选项
                                        while($rows=mysql_fetch_array($result))
                                        {?>
                                                <option value="<?php echo $rows['id']; ?>" ><?php echo $rows['name'];?></option>
                                        <?php } ?>
                        </select><br/><br/>
                        <label>&nbsp;&nbsp;&nbsp;&nbsp;专业：</label>
                        <select name="majorid" id="majorid" style="width:300px;">
                                <option value="-1">请选择专业</option>
                        </select><br/><br/>
					<div class="submit">
					<label></label><input type="submit" class="sub" value="确认提交" />&nbsp;&nbsp;&nbsp;&nbsp;<a class="lj" href="admin_department_major.php?do=main">返回列表</a>
                    </div>
            </fieldset>
			</form>
			</div>
			</td>
		</tr>
	</table>
<?php
}
?>






